package com.qyhl.webtv.module_microvideo.shortvideo.rank;

import com.qyhl.webtv.basiclib.utils.network.EasyHttp;
import com.qyhl.webtv.basiclib.utils.network.callback.SimpleCallBack;
import com.qyhl.webtv.basiclib.utils.network.exception.ApiException;
import com.qyhl.webtv.commonlib.entity.microvideo.ShortVideoBean;
import com.qyhl.webtv.module_microvideo.common.VideoUrl;

import java.util.List;

public class ShortVideoRankModel implements ShortVideoRankContract.ShortVideoRankModel {
    private ShortVideoRankPresenter mPresenter;

    ShortVideoRankModel(ShortVideoRankPresenter mPresenter) {
        this.mPresenter = mPresenter;
    }

    @Override
    public void getDataList(int type, String tagId, final String page) {
        String url = "";
        switch (type) {
            case 2:
                url = VideoUrl.GET_SHORT_VIDEO_HOUR_LIST;
                break;
            case 6:
                url = VideoUrl.GET_SHORT_VIDEO_WEEK_LIST;
                break;
            case 7:
                url = VideoUrl.GET_SHORT_VIDEO_TOTAL_LIST;
                break;
            default:
                url = VideoUrl.GET_SHORT_VIDEO_HOUR_LIST;
                break;
        }

        EasyHttp.get(url)
                .params("actId", tagId)
                .params("page", page)
                .execute(new SimpleCallBack<List<ShortVideoBean>>() {
                    @Override
                    public void onError(ApiException e) {
                        if (e.getCode() == 202) {
                            mPresenter.setError("暂无任何内容！", !page.equals("1"));
                        } else {
                            mPresenter.setError("请求出错，请重新获取！", !page.equals("1"));
                        }
                    }

                    @Override
                    public void onSuccess(List<ShortVideoBean> shortVideoBeans) {
                        if (shortVideoBeans!= null &&shortVideoBeans.size() > 0) {
                            mPresenter.setData(shortVideoBeans, !page.equals("1"));
                        } else {
                            mPresenter.setError("暂无任何内容！", !page.equals("1"));
                        }
                    }
                });
    }
}
